#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <fcntl.h>
#include <string.h>


int shell(char *c){
	pid_t pid;
	char sc[200];

	while (strcmp(sc,"exit")!=0 /*&& strcmp(sc,"quit")!=0*/){
		printf("%d > ",getpid());
		scanf("%s",sc);

		switch(pid=fork()){
			case 0:
				if (strcmp(sc,"list")==0){
					execlp("ls","ls",NULL);
				}
			
				else if (strcmp(sc,"monshell")==0){
					execlp(c,c,NULL);
				}
			
				else if (strcmp(sc,"processus")==0){
					execlp("top","top",NULL);
				}
			
				else {
					printf("La commande %s n'est pas connue par le shell\n", sc);
					return 0;
				}
				break;

			default:
				wait(NULL);
				break;
		}

	}
	return 0;
}


int main(int argc, char **argv){
	
	shell(argv[0]);

	return 0;
}
